package com.cloudfun.campusshare.common.response;

import com.cloudfun.campusshare.common.constant.Code;
import org.apache.poi.ss.formula.functions.T;

import java.text.MessageFormat;

/**
 * Created by linyangping on 2019/10/21.
 * baseResult工程方法
 */
public final class BaseResultFactory {

    public static BaseResult<?> produceSuccess() {
        return new BaseResult<>(Code.SUCCESS);
    }

    public static <T> BaseResult<T> produceSuccess(T data) {
        return new BaseResult<>(Code.SUCCESS, data);
    }

    public static BaseResult<?> produceEmptyResult(Code code) {
        return new BaseResult<>(code);
    }

    public static BaseResult<?> produceEmptyResult(Code code, String msg) {
        return new BaseResult<>(code.getCode(), msg);
    }

    public static BaseResult<?> produceEmptyResult(int codeInt, String msg) {
        return new BaseResult<>(codeInt, msg);
    }

    public static <T> BaseResult<T> produceResult(int codeInt, String msg, T data) {
        return new BaseResult<>(codeInt, msg, data);
    }

    public static <T> BaseResult<T> produceResult(Code code, T data) {
        return new BaseResult<>(code.getCode(), code.getMsg(), data);
    }

    /**
     *
     * @param code
     * @param content 占位符需要替换的内容
     * @return
     */
    public static BaseResult producrErrorResult(Code code,Object[] content){
        String message = MessageFormat.format(code.getMsg(), content);
        code.setMsg(message);
        return new BaseResult(code);
    }
}
